home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / TouchMe 1.2□ / touchMe 1.2 Folder / touchMe source codes / CW11 PP source / source / Common Lib / UErrorMessage.cp < prev    next >
Encoding:
Text File  |  1997-04-25  |  2.0 KB  |  91 lines  |  [TEXT/CWIE]

  1. // ==================================================
  2. //    UErrorMessage.cp
  3. //    Copyright (C) 1994-1997 Mizutori Tetsuya
  4. //    March 9, 1994; July 4, 1996; February 3, 1997.
  5. // ==================================================
  6. //    All documents are pretty-printed in 10-point Geneva font.
  7.  
  8. #include <Resources.h>
  9. #include <Memory.h>
  10. #include <TextUtils.h>
  11. #include <Dialogs.h>
  12. #include <SegLoad.h>
  13. #include <Processes.h>
  14. #include <Notification.h>
  15. #include <Errors.h>
  16.  
  17. #include <UDesktop.h>
  18.  
  19. #include "UErrorMessage.h"
  20.  
  21.  
  22. const ResType    kErrorMessage_ResType        = 'ErrM';
  23.  
  24. const ResIDT    ALRT_ErrorBox                = 9000;
  25.  
  26.  
  27. // --------------------------------------------------
  28. //        • NofityIfOSErr
  29. // --------------------------------------------------
  30.  
  31. void
  32. UErrorMessage::NofityIfOSErr(
  33.     const OSErr    inErr,
  34.     const Boolean    inBeFatal )
  35. {
  36.     NofityIfOSErr( inErr, "\p", inBeFatal );
  37. }
  38.  
  39.  
  40. // --------------------------------------------------
  41. //        • NofityIfOSErr
  42. // --------------------------------------------------
  43.  
  44. void
  45. UErrorMessage::NofityIfOSErr(
  46.     const OSErr    inErr,
  47.     const Str255    inText,
  48.     const Boolean    inBeFatal )
  49. {
  50.  
  51.     if ( inErr == noErr ) return;
  52.  
  53.     Str31    theErrNumber;
  54.     Str255    theResName;
  55.     Str255    theErrMessage;
  56.     Handle    theResourceH;
  57.  
  58.     theResourceH = ::GetResource( kErrorMessage_ResType, (short) inErr );
  59.     if ( theResourceH != nil ) {
  60.         short        theID;
  61.         ResType    theType;
  62.         ::GetResInfo( theResourceH, &theID, &theType, theResName );
  63.         theErrMessage[0] = ::GetHandleSize( theResourceH );
  64.         ::BlockMoveData( (Ptr) *theResourceH, &theErrMessage[0], theErrMessage[0] );
  65.         ::ReleaseResource( theResourceH );
  66.     } else {
  67.         theResName[0] = 0;
  68.         theErrMessage[0] = 0;
  69.     }
  70.  
  71.     ::NumToString( inErr, theErrNumber );
  72.  
  73.     ::ParamText( theResName, theErrNumber, theErrMessage, inText );
  74.  
  75.     // Deactivate the desktop.
  76.     UDesktop::Deactivate();
  77.  
  78.     if ( inBeFatal ) {
  79.         ::StopAlert( ALRT_ErrorBox, nil );
  80.         ::ExitToShell();
  81.     } else {
  82.         ::NoteAlert( ALRT_ErrorBox, nil );
  83.     }
  84.  
  85.     // Activate the desktop.
  86.     UDesktop::Activate();
  87. }
  88.  
  89.  
  90. // end of program
  91.